package org.yaac.shared.cap;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class CapSummaryDTO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @author Max Zhu (thebbsky@gmail.com)
	 *
	 */
	public enum Status {
		ENABLED, 
		SCHEDULED_MAINTENANCE, 
		DISABLED, 
		UNKNOWN
	}
	
	public static class Capability implements Serializable {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		private String packageName;
		
		private String name;
		
		private Status status;

		/**
		 * used by GWT
		 */
		@SuppressWarnings("unused")
		private Capability() {}
		
		public Capability(String packageName, String name, Status status) {
			super();
			this.packageName = packageName;
			this.name = name;
			this.status = status;
		}

		public String getName() {
			return name;
		}

		public Status getStatus() {
			return status;
		}
		
		public String getPackageName() {
			return packageName;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((name == null) ? 0 : name.hashCode());
			result = prime * result + ((packageName == null) ? 0 : packageName.hashCode());
			result = prime * result + ((status == null) ? 0 : status.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Capability other = (Capability) obj;
			if (name == null) {
				if (other.name != null)
					return false;
			} else if (!name.equals(other.name))
				return false;
			if (packageName == null) {
				if (other.packageName != null)
					return false;
			} else if (!packageName.equals(other.packageName))
				return false;
			if (status != other.status)
				return false;
			return true;
		}

		@Override
		public String toString() {
			return "Capability [packageName=" + packageName + ", name=" + name + ", status=" + status + "]";
		}
	}

	public List<Capability> caps;
	
	public CapSummaryDTO() {
		this.caps = new LinkedList<Capability>();
	}
	
	public void setStatus(String packageName, String  name, Status status) {
		this.caps.add(new Capability(packageName, name, status));
	}
	
	public List<Capability> caps() {
		return this.caps;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((caps == null) ? 0 : caps.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CapSummaryDTO other = (CapSummaryDTO) obj;
		if (caps == null) {
			if (other.caps != null)
				return false;
		} else if (!caps.equals(other.caps))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "OverviewDTO [caps=" + caps + "]";
	}
}
